from flask import g, redirect, url_for
from functools import wraps


# 提高代码复用
def login_required(func):
    # ??? wraps
    @wraps(func)
    def wapper(*args, **kwargs):
        if hasattr(g, 'user'):
            return func(*args, **kwargs)
        else:
            return redirect(url_for('user.login'))
    return wapper
